#include "../../config.h"

#include <iostream>

#include "../url.h"
#include "../log.h"

using namespace gpyp;

void test(const std::string &url) {
  try {
    std::cout << url << std::endl;
    std::cout << URL(url) << std::endl;
  } catch(const InvalidURL &ex) {
    std::cout << ex.what() << std::endl;
  }
  std::cout << std::endl;
}
bool base64_test(const std::string &str, const std::string &ans) {
  std::string enc;
  std::cout << " " << str;
  base64::encode(str, enc);
  bool res = enc == ans;
  std::cout << ": " << (res ? "OK" : "FAIL") << std::endl;
  return res;
}

int main() {
  /*
  test("http://:test@crckyl.ath.cx:2308/");
  test("http://id:pass@host:123/path?arg&n1=v1&n%202=v2");
  test("http://id@host:123/path?arg&n1=v1");
  test("http://:pass@host:123/path?arg&n1=v1");
  test("http://host:123/path?arg&n1=v1");
  test("http://host/path?arg&n1=v1");
  test("http://host/path");
  test("http://host");
  test("ftp://");
  test("ftp");
  */
  //gpyp::log::log << URL("http://:test@crckyl.ath.cx:2308/") << gpyp::log::endl;
  //std::cout << URL("http://:test@crckyl.ath.cx:2308/") << std::endl;

  std::cout << "Base64 test" << std::endl;
  if (!base64_test("hoge", "aG9nZQ==")) exit(1);
  if (!base64_test("id:pass", "aWQ6cGFzcw==")) exit(1);
  if (!base64_test("\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "44GC44GE44GG44GI44GK")) exit(1);
  return 0;
}
